import React from 'react';
import { Select } from 'antd';
import { useRequest, defaultFormatResult } from '@/hooks';
import { getJobList } from '@/services/organization';

const SelectPositionAndRank = props => {
    // 职位列表
    const { data: jobList } = useRequest(() => getJobList({ pageSize: 99999 }), {
        initialData: {},
        ...defaultFormatResult
    });

    return (
        <Select
            placeholder="请选择匹配职位"
            allowClear
            showSearch
            optionFilterProp="label"
            getPopupContainer={triggerNode => triggerNode.parentElement}
            filterOption={(input, option) => option.props.children.toLowerCase().indexOf(input.toLowerCase()) >= 0}
            {...props}
        >
            {jobList?.rows?.map(item => (
                <Select.Option value={item.positionCode} key={item.positionCode} label={item.positionName}>
                    {`${item.positionName}${item.rankValue ? '/' : ''}${item.rankValue}`}
                </Select.Option>
            ))}
        </Select>
    );
};

export default SelectPositionAndRank;
